package com.renge.ossservice.controller;

import com.renge.commonutils.R;
import com.renge.ossservice.service.OSSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(description="OSS文件管理")
@RestController
@CrossOrigin
@RequestMapping("/eduoss")
public class OSSController {
    @Autowired
    private OSSService ossService;

    @ApiOperation(value = "上传相片")
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        String uploadUrl = ossService.upload(file);
        if (uploadUrl!=null){
            return R.ok().data("avatar",uploadUrl);
        }
        return R.error();
    }

}
